package com.nf.teamwork.mall.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;
import java.security.PrivateKey;
import java.security.PublicKey;

/**
 * @Author: LJP
 * @Classname RsaKeyProperties
 * @Date: 2020-02-29 19:29
 * @Description: 该对象用来获取到公私钥
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ConfigurationProperties("rsa.key")
public class RsaKeyProperties {
    /*公私钥对象是通过公私钥文件路径获取的，
    如下两个字段就是用来获取yml文件中填入的公私钥文件路径*/
    private String pubKeyFile;
    private String priKeyFile;

    /*在这个类中主要为了获取到下面两个对象，公私钥对象*/
    private PublicKey publicKey;
    private PrivateKey privateKey;

    /**
     * 下面这个方法就是给公私钥对象赋值
     */
    //@PostConstruct：这个注解修饰的方法在RsaKeyProperties构造函数执行完后执行
    @PostConstruct
    public void createRsaKey() throws Exception {
        publicKey = RsaUtil.getPublicKey(pubKeyFile);
        privateKey = RsaUtil.getPrivateKey(priKeyFile);
    }
}
